package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingObjectDto;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingProjectMapper;
import com.zzyl.service.NursingProjectService;
import com.zzyl.vo.NursingProjectVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description NursingProjectServiceImpl
 * @Author lizhiwen
 * @Date 2024-09-06
 */

@Service
public class NursingProjectServiceImpl implements NursingProjectService {

    @Autowired
    private NursingProjectMapper nursingProjectMapper;

    @Override
    public PageResponse<NursingProjectVo> getByPage(String name, Integer status, Integer pageNum, Integer pageSize) {
        PageHelper.startPage(pageNum, pageSize);
        Page<NursingProject> page = nursingProjectMapper.selectByPage(name, status);
        PageResponse<NursingProjectVo> of = PageResponse.of(page, NursingProjectVo.class);

        return of;
    }

    @Override
    public void add(NursingObjectDto nursingObjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingObjectDto, NursingProject.class);

        nursingProjectMapper.add(nursingProject);
    }

    @Override
    public NursingProjectVo getById(Long id) {

        NursingProject nursingProject = nursingProjectMapper.getById(id);

        NursingProjectVo nursingProjectVo = BeanUtil.toBean(nursingProject, NursingProjectVo.class);
        return nursingProjectVo;
    }

    @Override
    public void update(NursingObjectDto nursingObjectDto) {
        NursingProject nursingProject = BeanUtil.toBean(nursingObjectDto, NursingProject.class);
        nursingProjectMapper.update(nursingProject);
    }

    @Override
    public void setStatus(Long id, Integer status) {
        nursingProjectMapper.setStatus(id, status);
    }

    @Override
    public List<NursingProjectVo> findAll() {
        List<NursingProjectVo> list = nursingProjectMapper.findAll();

        return  list;

    }
}
